/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.cemaden.agent.util;

import java.util.Date;

/**
 *
 * @author alan
 */
public class CalendarUtil {

    public static String getFormattedElapsedTime(Date startDate, Date endDate) {
        
        long elapsed = endDate.getTime() - startDate.getTime();

        long secondsInMilli = 1000;
        long minutesInMilli = secondsInMilli * 60;
        long hoursInMilli = minutesInMilli * 60;
        long daysInMilli = hoursInMilli * 24;

        long elapsedDays = elapsed / daysInMilli;
        elapsed = elapsed % daysInMilli;

        long elapsedHours = elapsed / hoursInMilli;
        elapsed = elapsed % hoursInMilli;

        long elapsedMinutes = elapsed / minutesInMilli;
        elapsed = elapsed % minutesInMilli;

        long elapsedSeconds = elapsed / secondsInMilli;

        return String.format("%d days, %d hours, %d minutes, %d seconds%n",
                elapsedDays, elapsedHours, elapsedMinutes, elapsedSeconds);
    }

}
